package ycj.learn.netty;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class TestByteBuffer {

    public static void main(String[] args) {
        try (FileChannel channel = new FileInputStream("pom.xml").getChannel()) {
            ByteBuffer buffer = ByteBuffer.allocate(10);

            while (channel.read(buffer) != -1) {

                /*切换读*/
                buffer.flip();

                while (buffer.hasRemaining()) {
                    System.out.print((char) buffer.get());
                }

                /*切换写*/
                buffer.flip();
            }

        } catch (Exception e) {
            /**/
        }
    }
}
